﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BLL;
using System.Collections.Generic;
public partial class admin_frame_Left : BLL.BasePage_Admin
{
    User_Volunteer bll_User_Volunteer = new User_Volunteer();
    Sys_Page bll_Sys_Page = new Sys_Page();
    Role bll_Role = new Role();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UIInit();
        }
    }

    private void UIInit()
    {
        Bind_Module();
    }

    private void Bind_Module()
    {
        //获取模块列表Level1
        DataTable dt = Get_Level1();
        if (dt != null)
        {
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
    }

    /// <summary>
    /// 获取权限列表Level1
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    private DataTable Get_Level1()
    {
        DataTable dt = null;
        if (string.IsNullOrEmpty(CurrentRole.PageIdList))
        {
            return dt;
        }
        if (CurrentRole.PageIdList != "*")
        {
            string sqlStr = "select * from dbo.Sys_Page where id in (select FartherId from dbo.Sys_Page where id in(" + CurrentRole.PageIdList + ")) and FartherId = " + QueryString_Int("id") + " order by OrderNum";
            dt = DAL.Common.Query(sqlStr);
        }
        else
        {
            dt = bll_Sys_Page.GetList("IsEnable = 1 and level = 1 and FartherId = " + Request.QueryString["Id"] + " order by OrderNum").Tables[0];
        }
        return dt;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater repeater2 = (Repeater)e.Item.FindControl("Repeater2");
            DataRowView level1 = (DataRowView)e.Item.DataItem;
            string sqlStr = string.Empty;
            if (CurrentRole.PageIdList != "*")
            {
                sqlStr = "select * from dbo.Sys_Page where IsEnable = 1 and id in (" + CurrentRole.PageIdList + ") and FartherId = " + level1["Id"].ToString() + "order by OrderNum";
            }
            else
            {
                sqlStr = "select * from dbo.Sys_Page where IsEnable = 1 and FartherId = " + level1["Id"].ToString() + " order by OrderNum";
            }
            repeater2.DataSource = DAL.Common.Query(sqlStr);
            repeater2.DataBind();
        }
    }
}
